package com.mnxc.gxa.controller;


import com.mnxc.gxa.dto.QueryDeptDTO;
import com.mnxc.gxa.dto.Result;
import com.mnxc.gxa.entity.Dept;
import com.mnxc.gxa.service.IDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mnxc
 * @since 2023-06-29
 */
@RestController
@RequestMapping("/dept")
@Api(tags="部门相关接口")
public class DeptController {
    @Resource
    IDeptService deptService;
    @GetMapping("/getAll")
    @ApiOperation(value = "获取部门接口",notes = "获取所有部门",httpMethod = "GET",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code = 1,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 0,message = "后台服务错误")
    })
    public Result getAll(){
        return deptService.getAll();
    }
    /*
     * @description: 分页查询
     * @author: mnxc
     * @date: 2023/6/30 11:12
     * @param: [page, pageSize, condition]
     * @return: com.mnxc.gxa.dto.Result
     **/

    @PostMapping
    @ApiOperation(value = "新增部门接口",notes = "新增部门",httpMethod = "POST",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code = 1,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 0,message = "后台服务错误")
    })
    public Result saveDept(@RequestBody Dept dept){
        return deptService.saveDept(dept);
    }

//    public Result getByPageAndCondition(int page,int pageSize,String condition){
//        return deptService.getByPageAndCondition(page,pageSize,condition);
//    }

    @DeleteMapping
    @ApiOperation(value = "删除部门接口",notes = "删除部门",httpMethod = "DELETE",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code = 1,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 0,message = "后台服务错误")
    })
    public Result deleteDept(Dept dept){
        return deptService.deleteDept(dept);
    }



    @GetMapping("/tree")
    public Result getDeptTree(){
        return deptService.getTree();
    }

    @PutMapping("/updateDept")
    @ApiOperation(value = "修改部门接口",notes = "修改部门",httpMethod = "PUT",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code = 1,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 0,message = "后台服务错误")
    })
    public Result updateDept(@RequestBody Dept dept){
        return deptService.updateDept(dept);
    }

    @PutMapping("/freeze")
    @ApiOperation(value = "冻结部门接口",notes = "冻结部门",httpMethod = "PUT",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code = 1,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 0,message = "后台服务错误")
    })
    public Result freezeDept(@RequestBody Dept dept){
        return deptService.freezeDept(dept);
    }

    @PutMapping("/active")
    @ApiOperation(value = "激活部门接口",notes = "激活部门",httpMethod = "PUT",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code = 1,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 0,message = "后台服务错误")
    })
    public Result activeDept(@RequestBody Dept dept){
        return deptService.active(dept);
    }

//    部门多选启用
    @GetMapping("/operate_active/{ids}")
    public Result operateByIds(@PathVariable List<Long> ids){
        return deptService.operateByIds(ids);
    }
    //    部门多选启用
    @GetMapping("/operate_freeze/{ids}")
    public Result operate_freezeByIds(@PathVariable List<Long> ids){
        return deptService.operate_freezeByIds(ids);
    }
    //部门多选逻辑删除
    @GetMapping("/operate_delete/{ids}")
    public Result operate_deleteByIds(@PathVariable List<Long> ids){
        return deptService.operate_deleteByIds(ids);
    }
    //通过状态和部门名称查找
    @ApiOperation(value = "分页查询接口",notes = "分页查询",httpMethod = "GET",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=0,message="后台服务错误")
    })
    @GetMapping("/getByCondition")
    public Result getByCondition( Integer page, Integer pageSize, QueryDeptDTO query) {
        return deptService.getByCondition(page, pageSize, query);
    }
}



